package cate.game.role.res.findback.impl;

import cate.common.table.d.GD;
import cate.common.table.d.GDDailyFb;
import cate.common.table.farm.dailyfb.DailyFbCombatRow;
import cate.common.table.findback.base.FindBackBaseRow;
import cate.game.res.MixRes;
import cate.game.role.farm.dailyfb.DailyFb;
import cate.game.role.res.findback.po.RoleFindBackFuncPO;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass("资源找回-日常副本")
public class RoleFindBackDailyFBPO extends RoleFindBackFuncPO {
    @NoteField("类型")
    public int type;

    public RoleFindBackDailyFBPO() {

    }

    @Override
    public int getFuncId() {
        return GDDailyFb.Type.toFuncId(type);
    }

    public RoleFindBackDailyFBPO(int type) {
        this.type = type;
    }

    @Override
    public void calcFindBack(boolean skipDay) {
        FindBackBaseRow config = getConfig();
        if (config == null) {
            return;
        }
        DailyFb dailyFb = role.getFarm().dailyFb.getFb(type);
        if (dailyFb == null) {
            return;
        }
        dailyFb.checkOpen();
        if (!dailyFb.open) {
            return;
        }
        if (dailyFb.combatNumPass <= 0) {
            return;
        }
        DailyFbCombatRow tpl = role.getGame().table.dailyFb.combat.find(dailyFb.type, dailyFb.combatNumPass);
        if (tpl == null) {
            return;
        }
        int findBackTimes = skipDay ?
                dailyFb.playTimes.getFreeTotal(role, getFuncId())
                : dailyFb.playTimes.getFreeRemain(role, getFuncId());
        if (findBackTimes > 0) {
            MixRes res = new MixRes(tpl.rewardSwapCode);
            if (!res.isEmpty()) {
                this.times = findBackTimes;
                this.freeReward = res.copy().multiplyDouble(config.rate / GD.W_10000_0);
                this.cost = new MixRes(config.costStr);
                this.payReward = res.copy();
            }
        }
    }
}
